package com.odm.communitymanage.ui.help

import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.ResourceUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.odm.communitymanage.R
import com.odm.communitymanage.core.bean.SeekHelpData
import com.odm.communitymanage.util.GlideUtils
import com.odm.communitymanage.widget.AvatarModeUtils

/**
 * @description: 求助列表 适配器
 * @author: ODM
 * @date: 2020/4/18
 */
class SeekHelpAdapter(data : MutableList<SeekHelpData>)
    :BaseQuickAdapter<SeekHelpData,BaseViewHolder>(R.layout.item_help_summary,data){

    override fun convert(holder: BaseViewHolder, item: SeekHelpData) {
        holder.setText(R.id.tvContactInfo_HelpSummary  , item.username+ " "+item.phone)
        holder.setText(R.id.tvTime_HelpSummary ,item.time)
        holder.setText(R.id.tvContent_HelpSummary,item.content)
        if(item.status == 0){
            //未解决
            holder.setText(R.id.tvState_HelpSummary , context.getString(R.string.unsloved))
//            holder.setTextColor(R.id.tvState_HelpSummary , R.color.help_unsloved)  直接设置无效
            holder.getViewOrNull<TextView>(R.id.tvState_HelpSummary)?.setTextColor(ColorUtils.getColor(R.color.help_unsloved))

        }else if(item.status == 1){
            //已解决
            holder.setText(R.id.tvState_HelpSummary , context.getString(R.string.solved))
            holder.getViewOrNull<TextView>(R.id.tvState_HelpSummary)?.setTextColor(ColorUtils.getColor(R.color.help_solved))
        }

        //加载用户的默认头像
        val avatarView  : ImageView ?= holder.getView(R.id.ivAvatar_HelpSummary)
        avatarView?.let {
            val name = item.username
            if(name != ""){
                //加载仿钉钉头像
                val para: ViewGroup.LayoutParams = it.layoutParams
                val w = para.width
                val h = para.height
                GlideUtils.getInstance().loadBitmap(
                    context,
                    AvatarModeUtils.getAvatar(arrayListOf(name[0].toString()) as List<Any>?, w , h),
                    it
                )
            }
        }

        
    }
}